package numberThree;


import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

class Corporation{
    public int getAllPeople() {
        return allPeople;
    }

    public void setAllPeople(int allPeople) {
        this.allPeople = allPeople;
    }

    public int getNumberPeople() {
        return numberPeople;
    }

    public void setNumberPeople(int numberPeople) {
        this.numberPeople = numberPeople;
    }

    private int allPeople=10000;
    private int numberPeople=0;
    public synchronized int enter(){
        if (this.getNumberPeople()==getAllPeople()){
            return -1;
        }
        int count=this.getNumberPeople()+1;
        this.setNumberPeople(count);
        Thread thread = Thread.currentThread();
        String s = DoubleColorBallUtil.create();
        System.out.println("编号为:"+count+"的员工从"+thread.getName()+"入场! 拿到的双色球彩票号码是 :"+s );
        return 1;
    }
}

public class NumberThree {
    public static void main(String[] args) {
        Corporation corporation=new Corporation();
        FutureTask futureTask=new FutureTask(()->{
            int i=0;
            while (true){
                int enter = corporation.enter();
                if (enter==-1){
                  break;
                }
                i++;
            }
            return i;
        });
        Thread thread=new Thread(futureTask,"前门");
        thread.start();
        FutureTask futureTask1=new FutureTask(()->{
            int i=0;
            while (true){
                int enter = corporation.enter();
                if (enter==-1){
                    break;
                }
                i++;
            }
            return i;
        });
        Thread thread1=new Thread(futureTask1,"后门");
        thread1.start();
        try {
            System.out.println(futureTask.get());
            System.out.println(futureTask1.get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

}
